package com.yanqu.road.server.cmd.guess.group;

import com.yanqu.road.exception.BusinessException;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.activity.CommonGuessProto;
import com.yanqu.road.server.cmd.CrossCommand;
import com.yanqu.road.server.cmd.CrossUnionCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.logic.MessageHelper;
import com.yanqu.road.server.manager.guess.CrossCommonGuessMgr;
import com.yanqu.road.server.protocol.Protocol;
import com.yanqu.road.utils.YanQuMessageUtils;

@Cmd(code = Protocol.C2_COMMON_GUESS_GET_RECEIVE_REWARD_GROUP, desc = "通用竞猜-领取奖励-商会分组活动")
public class CrossCommonGuessReceiveRewardGroupCmd extends CrossUnionCommand {

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        return true;
    }

    @Override
    public void execute(YanQuMessage packet) throws Exception {
        CommonGuessProto.CommonGuessReceiveRewardReqMsg reqMsg = CommonGuessProto.CommonGuessReceiveRewardReqMsg.parseFrom(packet.getBytes());
        try {
            String reward = CrossCommonGuessMgr.receiveReward(packet.getPlayerId(), groupId, reqMsg);
            CommonGuessProto.CommonGuessReceiveRewardFromCrossReqMsg.Builder serverReqMsg = CommonGuessProto.CommonGuessReceiveRewardFromCrossReqMsg.newBuilder();
            serverReqMsg.setActivityId(reqMsg.getActivityId());
            serverReqMsg.setGroupId(groupId);
            serverReqMsg.setRound(reqMsg.getRound());
            serverReqMsg.setSiteId(reqMsg.getSiteId());
            serverReqMsg.setReward(reward);
            //返回区服保存数据
            MessageHelper.sendPacket(serverId, packet.getPlayerId(), YanQuMessageUtils.buildMessage(Protocol.S_COMMON_GUESS_RECEIVE_REWARD_FROM_CROSS, serverReqMsg));
        } catch (BusinessException e) {
            CommonGuessProto.CommonGuessReceiveRewardRespMsg.Builder respMsg = CommonGuessProto.CommonGuessReceiveRewardRespMsg.newBuilder();
            respMsg.setRet(e.getCode());
            MessageHelper.sendPacket(serverId, packet.getPlayerId(), YanQuMessageUtils.buildMessage(Protocol.U_COMMON_GUESS_RECEIVE_REWARD, respMsg));
        }
    }

    @Override
    public void sendData() {

    }
}
